from flask import Flask
from plugins.jwt import TokenManager
import hashlib


def token_manager(app: Flask):
    SECRET_KEY = app.config.get("SECRET_KEY")
    refresh_expires = app.config.get("TOKEN_REFRESH_EXPIRES")
    expires = app.config.get("TOKEN_EXPIRES")
    return TokenManager(secret_key=SECRET_KEY, expires=expires, refresh_expires=refresh_expires)


def get_hash_pwd(string: str, app: Flask) -> str:
    """
    字符串加密
    :param app:
    :param string: 字符串
    :return:
    """
    SECRET_KEY = app.config.get("SECRET_KEY")
    md5 = hashlib.md5(bytes(SECRET_KEY, encoding="utf8"))  # 加盐
    md5.update(string.encode(encoding='UTF-8'))
    return md5.hexdigest()
